﻿using System;
using System.Collections;
using UnityEngine;

public class GameAdManager
{

    private static bool isRuning;
    public static bool isDebug = false;

    public static void MainBanner()
    {
        if (isDebug) return;
        if (!AdManager.Instance.ShieldAddress)
        {
            AdManager.Instance.ShowBanner();
        }
    }

    public static void StartGame(Action action)
    {
        if (isDebug)
        {
            action?.Invoke();
            return;
        }
        if (isRuning) return;
        if (!AdManager.Instance.ShieldAddress)
        {
            isRuning = true;
            Time.timeScale = 1;
            CheckTouch.Show(delegate
            {
                isRuning = false;
                action.Invoke();
            });
        }
        else
        {
            action.Invoke();
        }
    }

    public static void NewScene()
    {
        if (isDebug) return;
        if (!AdManager.Instance.ShieldAddress)
        {
            AdManager.Instance.ShowNative();
        }
    }

    public static void Pause()
    {
        if (isDebug) return;
        if (!AdManager.Instance.ShieldAddress)
        {
            AdManager.Instance.ShowNative(0f);
        }
    }

    public static void EndGame(MonoBehaviour monoBehaviour, Action action)
    {
        if (isDebug)
        {
            action?.Invoke();
            return;
        }
        if (!AdManager.Instance.ShieldAddress)
        {
            Time.timeScale = 1;
            monoBehaviour.StartCoroutine(ShowBox(action));
        }
        else
        {
            action?.Invoke();
            AdManager.Instance.ShowNative(0f);
        }
    }

    private static IEnumerator ShowBox(Action action)
    {
        yield return new WaitForSeconds(1);
        CheckTouch.Show(action);
    }



}
